package com.sg.hms.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.sg.hms.Model.Role;
import com.sg.hms.Model.User;
import com.sg.hms.Service.FoodMenuService;
import com.sg.hms.ServiceImpl.FoodMenuServiceImpl;
/**
 * 
 * @author 张杨
 *
 */
public class FindfoodMenuController extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		PrintWriter pw=resp.getWriter();
		JSONObject foodmenus=new JSONObject();
		FoodMenuService fmservice=new FoodMenuServiceImpl();
		HttpSession session=req.getSession();
	
		int page=Integer.parseInt(req.getParameter("page"));
	
		int pageSize=Integer.parseInt(req.getParameter("rows"));
	
		int start=(page-1)*pageSize;
		
		Role role=(Role) session.getAttribute("currentrole");
		int rid=role.getRoleId();
	
		String searchname=req.getParameter("searchname");
		if (searchname!=null) {
			foodmenus=fmservice.getFoods(start, pageSize, rid, searchname);
		}else {
			foodmenus=fmservice.getFoods(start, pageSize,rid);
		}
		pw.write(foodmenus.toString());

	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}
}
